from manim import *
from pathlib import Path
import os

# 说明：pql生成480p视频，pqm生成720p视频，pqh生成1080p视频，pqk生成4k视频
# 测试时生成低质量会快点，测试完成后再生成高质量视频
FLAGS = f"-pql"
SCENE = "Scene"

COLORS = ('#55F1F1', '#F18455', '#F1F155', YELLOW)
MarkupText.set_default(font_size = 28)

def f(self, word, d1_text, d2_text, e):
    
    word = Title(word)
    word.shift(DOWN * 0.8)
    word.set_color(COLORS[3])
    self.play(Write(word))
    self.wait(10)

    d1 = VGroup(
        MarkupText("描述1: "), 
        MarkupText(d1_text)
    ).arrange(RIGHT)

    d2 = VGroup(
        MarkupText("描述2: "),
        MarkupText(d2_text)
    ).arrange(RIGHT)

    d = VGroup(d1, d2).arrange(DOWN, buff = 0.5)
    d.next_to(word, DOWN * 1.5)
    d.set_color(COLORS[0])

    self.play(FadeIn(d))
    self.wait(10)
    self.play(d.animate.scale(0.6))

    e[0].next_to(d, DOWN * 2)
    for i in range(1, len(e)):
        e[i].move_to(e[i-1])

    for i in range(len(e)):
        self.play(FadeIn(e[i]))
        self.wait(10)
        if (i < (len(e)-1)):
            self.play(FadeOut(e[i]))
        else:
            self.play(FadeOut(word, d, e[i]))


class Scene(Scene):
    def construct(self):
        word = "assumption"
        d1 = "something that you accept as true without question or proof"
        d2 = "If you make an assumption that something is true or will happen, \n you accept that it is true or will happen, often without any real proof."

        e = VGroup(
            MarkupText(f'They make the naive <span fgcolor="{COLORS[3]}">assumption</span> that because it\'s popular it must be good.'),
            MarkupText(f'Lots of evidence supports this <span fgcolor="{COLORS[3]}">assumption</span>.'),
            MarkupText(f'I really don\'t like you making <span fgcolor="{COLORS[3]}">assumptions</span> about what I think.'),
            MarkupText(f'She\'s always making <span fgcolor="{COLORS[3]}">assumptions</span> about how much money people have.'),
            MarkupText(f'The <span fgcolor="{COLORS[3]}">assumptions</span> made about the economy\'s rate of growth \n proved to be incorrect.'),
        )

        f(self, word, d1, d2, e)


if __name__  == '__main__':
    script_name = f"{Path(__file__).resolve()}"
    os.system(f"manim {FLAGS} {script_name} {SCENE}")